//
//  LGPatientDetailController_YHJK.m
//  HeartDisease_YHJK
//
//  Created by 1234 on 2024/12/17.
//

#import "LGPatientDetailController_YHJK.h"

//基本资料
#import "LGPatientBasicInfoController.h"
//电话随访
#import "LGMedicineBallPhoneController.h"
//团队咨询
#import "TUIGroupChatViewController.h"
#import "TUIChatConversationModel.h"
//新增随访计划
#import "LGLungFollowSendController.h"
//查看随访详情
#import "LGCancerPatientFollowController.h"
//运动康复
#import "LGSportsRecordController.h"
//治疗记录
#import "LGCancerTreatRecordController.h"
//报告中心
#import "LGReportingCenterController.h"
#import "LGEvaluationReportController.h"
//体征监测
#import "LGCancerMonitoringController.h"
//生活记录方式
#import "LGLifelogViewController.h"
//呼吸训练统计
#import "LGBreathRecordController.h"
//随访及医嘱记录
#import "LGFollowAdviceRecordController.h"
//照护计划
#import "LGPatientCarePlanController.h"
//药球详情
#import "LGMedicineBallDetailController.h"
//开具医嘱
#import "LGAddDoctorAdviceController.h"
//添加随访总结
#import "LGMedicineBallFollowUpRecorder.h"
//建设中
#import "LGEmptyViewController.h"
#import "LGCancerPatientDetailHeader.h"
#import "LGPatientClinicRecordCell.h"
#import "LGConsultRecordSurgeryCell.h"
#import "LGPatientDetailPlanCell.h"

#import "LGCancerPatientDetailFollowView.h"
#import "LGCancerPatientDetailItemView.h"
#import "LGPatientDetailMedicineView.h"
#import "LGPatientDetailItemView.h"
#import "LGPatientDetailFollowCell.h"
@interface LGPatientDetailController_YHJK ()<UITableViewDelegate,UITableViewDataSource,LGCancerPatientDetailItemDelegate,LGPatientDetailMedicineDelegate>
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)UIView *tableHeaderView;
/**  底部-工作台 */
@property (nonatomic , strong)UIView *bottomView;
@property (nonatomic , strong)UIView *bottomItemView;
@property (nonatomic , strong)UIButton *openButton;
/**  患者详情 */
@property (nonatomic , strong)LGCancerPatientDetailHeader *headView;
/**  随访计划 */
@property (nonatomic , strong)LGCancerPatientDetailFollowView *followView;
/**  随访及医嘱记录 */
@property (nonatomic , strong)LGPatientDetailItemView *followupView;
/** 测评记录、运动康复、检验检测报告、体征检测、呼吸训练记录 */
@property (nonatomic , strong)LGCancerPatientDetailItemView *itemView;
/**  服药情况 */
@property (nonatomic , strong)LGPatientDetailMedicineView *medicineView;

/**   */
@property (nonatomic , strong)NSDictionary *careplanDic;

/**  服药记录 */
@property (nonatomic , strong)NSArray *medicineArray;
@property (nonatomic , strong)NSDictionary *medicineDic;
@property (nonatomic , assign)NSInteger medicineIndex;
@property (nonatomic , copy)NSString *medicineid;
@property (nonatomic , strong)NSDateFormatter *formatter;

/**   */
@property (nonatomic , strong)UIButton *followBtn;
/**   */
@property (nonatomic , strong)NSArray *followArray;
/**   */
@property (nonatomic , assign)BOOL followOpen;

@end

@implementation LGPatientDetailController_YHJK

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationView.title = @"患者档案";
    [self createSubView];
    self.followupView.hidden = ([self.diseaseCode isEqualToString:@"4"]||[self.diseaseCode isEqualToString:@"11"])?YES:NO;
    CGFloat marginTop = ([self.diseaseCode isEqualToString:@"4"]||[self.diseaseCode isEqualToString:@"11"])?viewPix(8):viewPix(93);
    CGFloat height = ([self.diseaseCode isEqualToString:@"4"]||[self.diseaseCode isEqualToString:@"11"])?viewPix(815):viewPix(908);
    height = ([self.diseaseCode isEqualToString:@"3"] || [self.diseaseCode isEqualToString:@"6"])?height-viewPix(80):height;
    CGFloat itemHeight = ([self.diseaseCode isEqualToString:@"3"] || [self.diseaseCode isEqualToString:@"6"])?viewPix(190):viewPix(270);
    self.tableHeaderView.frame = CGRectMake(0, 0, Screen_W, height);
    [self.itemView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.followView.mas_bottom).offset(marginTop);
        make.height.equalTo(@(itemHeight));
    }];
    self.tableView.tableHeaderView = self.tableHeaderView;
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.levelid = (_levelid && ![_levelid isEmptyString])?_levelid:@"";
    [self requestData];
    [self requestFollowData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/patient.Patient/dtxPatientIndex" parameters:@{@"patient_id":self.patientid,@"level_id":self.levelid} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            self.careplanDic = returnData;
//            self.diseaseCode = LGNSString(returnData[@"patient"][@"disease_code"]);
            self.itemView.diseaseCode = self.diseaseCode;
           
            //个人信息
            self.headView.dataDic = returnData[@"patient"];
            //随访计划
            self.followView.dataDic = returnData[@"care_tasks"];
            //按钮
            self.itemView.dataDic = returnData;
            //服药记录
            self.medicineView.medicineArray = returnData[@"medicines"][@"medicines"];
            self.medicineView.currentIndex = self.medicineIndex;
            self.medicineView.dataDic = returnData[@"medicines"];
            
            CGFloat followH = ([self.diseaseCode isEqualToString:@"4"]||[self.diseaseCode isEqualToString:@"11"])?viewPix(795):viewPix(888);
            NSArray *followArray = @[];
            NSDictionary *careDic = returnData[@"care_tasks"];
            if (careDic.allKeys.count>0 && [careDic.allKeys containsObject:@"items"]) {
                followArray = careDic[@"items"];
            }
            NSInteger count = (followArray.count>0)?followArray.count:1;
            followH += viewPix(25)*count;
            self.followupView.frame = CGRectMake(viewPix(16),kMaxY(self.followView.frame)+viewPix(15), Screen_W-viewPix(32), viewPix(75));
            self.tableHeaderView.frame = CGRectMake(0, 0, Screen_W, followH);
            self.tableView.tableHeaderView = self.tableHeaderView;
        }
    } error:^(NSError *error) {
        
    }];
}

//请求随访记录列表
-(void)requestFollowData{
    [RequestUtil withPOST:@"/doctor/patient.profile/bzRecordAll" parameters:@{@"patient_id":self.patientid,@"level_id":self.levelid} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if (code == 200) {
            self.followArray = returnData;
        }
        [self.tableView reloadData];
    } error:^(NSError *error) {
        
    }];
}

//请求服药记录
-(void)requestMedicine:(NSString *)medicineid index:(NSInteger)index{
    self.medicineid = medicineid;
    self.medicineIndex = index;
    [self requestMedicineChartData:@"medicine"];
}

//服药统计图
-(void)requestMedicineChartData:(NSString *)type{
    [RequestUtil withPOST:@"/doctor/Sportsprescription.MedicinePrescription/medicineStatistics" parameters:@{@"patient_id":self.patientid,@"compliance_range":@"90",@"medicine_id":self.medicineid,@"symptom_range":[self.formatter stringFromDate:[NSDate date]],@"level_id":self.levelid} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            self.medicineView.dataDic = returnData;
        }
    } error:^(NSError *error) {
        
    }];
}

//查看患者基本信息
-(void)checkPatientInfoAction{
    LGPatientBasicInfoController *controller = [[LGPatientBasicInfoController alloc]init];
    controller.patientid = self.patientid;
    controller.diseaseCode = self.diseaseCode;
    controller.levelid = self.levelid;
    [self.navigationController pushViewController:controller animated:YES];
}

//团队咨询
-(void)consultButtonAction{
    __weak typeof(self) weakSelf = self;
    [LGAlertTool closeAlertWithTitle:@"提示" content:@"将为患者开启一次团队咨询（不消耗服务次数）" sureTitle:@"确认开启" sureAction:^{
        [RequestUtil withPOST:@"/doctor/visit.visit/createTeamAppointment" parameters:@{@"patient_id":weakSelf.patientid,@"level_id":weakSelf.levelid} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
            if(code == 200){
                NSMutableArray *tempArray = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
                for (UIViewController *controller in tempArray) {
                    if([controller isKindOfClass:[TUIGroupChatViewController class]]){
                        [tempArray removeObject:controller];
                        break;
                    }
                }
                self.navigationController.viewControllers = tempArray;
                TUIChatConversationModel *model = [[TUIChatConversationModel alloc]init];
                model.title = LGNSString(returnData[@"patient"][@"realname"]);
                model.groupID = LGNSString(returnData[@"im_group_id"]);
                TUIGroupChatViewController *controller = [[TUIGroupChatViewController alloc]init];
                controller.appointment_id = LGNSString(returnData[@"appointment_id"]);
                controller.doctorid = LGNSString(returnData[@"system_user_id"]);
                controller.roomKey = model.groupID;
                controller.needCustomeData = YES;
                [controller setConversationData:model];
                [weakSelf.navigationController pushViewController:controller animated:YES];
            }else{
                [TooltipView showMessage:message offset:0];
            }
        } error:^(NSError *error) {
            [TooltipView showMessage:@"请求失败，请重试" offset:0];
        }];
    }];
}

//电话随访
-(void)phoneFollowUpAction{
    LGMedicineBallPhoneController *controller = [[LGMedicineBallPhoneController alloc]init];
    controller.patientid = self.patientid;
    controller.planid = @"0";
    controller.levelid = self.levelid;
    [self.navigationController pushViewController:controller animated:YES];
}

//新增随访计划
-(void)addFollowUpAction{
    LGLungFollowSendController *controller = [[LGLungFollowSendController alloc]init];
    controller.patientid = self.patientid;
    controller.levelid = self.levelid;
    [self.navigationController pushViewController:controller animated:YES];
}

//查看随访详情
-(void)checkFollowUpDetailAction{
    LGCancerPatientFollowController *controller = [[LGCancerPatientFollowController alloc]init];
    controller.baseDate = LGNSString(self.careplanDic[@"next_careplan_date"]);
    controller.planid = ([self.followView.dataDic[@"is_checked"] integerValue]==0)?@"":LGNSString(self.careplanDic[@"patient_careplan_id"]);
//    controller.canEdit = ([self.followView.dataDic[@"is_checked"] integerValue]==0)?YES:NO;
    controller.canEdit = YES;
    controller.patientid = self.patientid;
    controller.levelid = self.levelid;
    [self.navigationController pushViewController:controller animated:YES];
}

//随访及医嘱记录
-(void)checkFollowupRecord{
    LGFollowAdviceRecordController *controller = [[LGFollowAdviceRecordController alloc]init];
    controller.patientid = self.patientid;
    controller.levelid = self.levelid;
    [self.navigationController pushViewController:controller animated:YES];
}

//测评记录
-(void)checkEvaluationRecord{
    LGEvaluationReportController *controller = [[LGEvaluationReportController alloc]init];
    controller.patientid = self.patientid;
    controller.title = @"测评记录";
    [controller viewWillAppearAction];
    [self.navigationController pushViewController:controller animated:YES];
}

//检查报告
-(void)checkInspectionReport{
    LGReportingCenterController *controller = [[LGReportingCenterController alloc]init];
    controller.patientid = self.patientid;
    controller.diseaseCode = self.diseaseCode;
    controller.currentIndex = 2;
    [self.navigationController pushViewController:controller animated:YES];
}

//体征监测
-(void)checkMonitorData{
    LGCancerMonitoringController *controller = [[LGCancerMonitoringController alloc]init];
    controller.patientid = self.patientid;
    controller.diseaseCode = self.diseaseCode;
    [self.navigationController pushViewController:controller animated:YES];
}

//生活记录方式
-(void)checkSportsController{
    LGSportsRecordController *controller = [[LGSportsRecordController alloc]init];
    controller.patientid = self.patientid;
    controller.levelid = self.levelid;
    [self.navigationController pushViewController:controller animated:YES];
}

//治疗记录
-(void)checkTreatReocrd{
    // 1-手术、 2-放疗、 3-化疗、 4-靶向治疗、 5-免疫治疗、 6-内分泌治疗、 7-中医治疗、 8-介入治疗、 9-其他治疗
    LGCancerTreatRecordController *controller = [[LGCancerTreatRecordController alloc]init];
    controller.patientid = self.patientid;
    controller.levelid = self.levelid;
    [self.navigationController pushViewController:controller animated:YES];
}

//呼吸训练记录
-(void)checkBreathRecord{
    LGBreathRecordController *controller = [[LGBreathRecordController alloc]init];
    controller.patientid = self.patientid;
    [self.navigationController pushViewController:controller animated:YES];
}

//查看、创建 照护计划
-(void)checkPlanAction{
    LGPatientCarePlanController *controller = [[LGPatientCarePlanController alloc]init];
    controller.diseaseCode = self.diseaseCode;
    controller.patientid = self.patientid;
    [self.navigationController pushViewController:controller animated:YES];
}

-(void)bottomItemButtonAction:(UIButton *)sender{
    NSInteger index = sender.tag - 1000;
    if (index == 0){
        //开具医嘱
        LGAddDoctorAdviceController *controller = [[LGAddDoctorAdviceController alloc]init];
        controller.patientid = self.patientid;
        controller.followid = @"";
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if (index == 1){
        //添加随访总结
        LGMedicineBallFollowUpRecorder *controller = [[LGMedicineBallFollowUpRecorder alloc]init];
        controller.planid = @"0";
        controller.patientid = self.patientid;
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if (index == 2){
        //开启团队咨询
        [self consultButtonAction];
        
    }else if (index == 3){
        //电话随访
        [self phoneFollowUpAction];
    }
}

//操作台-展开、收起
-(void)openButtonAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    [sender setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:3];
    CGFloat height = viewPix(50)+bottomSafeBarHeight/2.0;
    if (sender.selected == YES) {
        height = (isPad==YES)?(viewPix(110)+bottomSafeBarHeight/2.0):(viewPix(150)+bottomSafeBarHeight/2.0);
    }
    [UIView animateWithDuration:0.4 animations:^{
        self.bottomView.frame = CGRectMake(0, Screen_H-topBarHeight-height, Screen_W, height);
        self.bottomItemView.alpha = (sender.selected == YES)?1:0;
    }];
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //随访记录
    NSInteger maxCount = (self.followArray.count>3)?3:self.followArray.count;
    return (self.followOpen == YES)? self.followArray.count:maxCount;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //随访记录
    LGPatientDetailFollowCell *followCell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    followCell.selectionStyle = UITableViewCellSelectionStyleNone;
    followCell.dataDic = self.followArray[indexPath.row];
    return followCell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (self.followArray.count>0){
        //随访记录
        return viewPix(55);
    }
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    CGFloat height = 0.01;
    NSString *title = @"";
    if (self.followArray.count>0){
        //治疗记录
        height = viewPix(55);
        title = @"随访记录";
    }
    
    LGCornerHeaderView *headView = [[LGCornerHeaderView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, height)];
    headView.topMargin = viewPix(10);
    if (height>2) {
        UIImageView *iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"患者档案-癌症区头"]];
        [headView addSubview:iconView];
        UILabel *titleLabel = [UILabel lableWithText:title colorString:@"#282828" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        [headView addSubview:titleLabel];
        [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(headView.shadowView).offset(viewPix(16));
            make.left.equalTo(headView.shadowView);
            make.width.equalTo(@(viewPix(4)));
            make.height.equalTo(@(viewPix(16)));
        }];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(iconView.mas_right).offset(viewPix(8));
            make.centerY.equalTo(iconView);
        }];
    }
    return headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    CGFloat height = 0;
    if (self.followArray.count>0){
        //随访记录
        height = viewPix(45);
    }
    return height;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    CGFloat height = 0;
    if (self.followArray.count>0){
        //随访记录
        height = viewPix(45);
    }
    LGCornerFooterView *footView = [[LGCornerFooterView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, height)];
    footView.bottomMargin = viewPix(8);
    if (section == 4) {
        [footView addSubview:self.followBtn];
    }
    return footView;
}

//查看更多随访记录
-(void)checkMoreFollowRecords:(UIButton *)sender{
    sender.selected = !sender.selected;
    self.followOpen = sender.selected;
    [self.tableView reloadData];
    [self.followBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:3];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.title = @"患者档案";
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomView];
    [self createBottomView];
    [self.tableHeaderView addSubview:self.headView];
    [self.tableHeaderView addSubview:self.followView];
    [self.tableHeaderView addSubview:self.followupView];
    [self.tableHeaderView addSubview:self.itemView];
    [self.tableHeaderView addSubview:self.medicineView];
    self.tableView.tableHeaderView = self.tableHeaderView;
    [self.itemView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.followView.mas_bottom).offset(viewPix(8));
        make.left.right.equalTo(self.view);
        make.height.equalTo(@(viewPix(270)));
    }];
    [self.medicineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.itemView.mas_bottom).offset(viewPix(8));
        make.left.equalTo(self.view).offset(viewPix(16));
        make.right.equalTo(self.view).offset(-viewPix(16));
        make.height.equalTo(@(viewPix(320)));
    }];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.bottom.equalTo(self.bottomView.mas_top);
    }];
}

-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGPatientDetailFollowCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = self.tableHeaderView;
    }
    return _tableView;
}

-(UIView *)tableHeaderView{
    if(!_tableHeaderView){
        _tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(815))];
    }
    return _tableHeaderView;
}

-(LGCancerPatientDetailHeader *)headView{
    if(!_headView){
        _headView = [[LGCancerPatientDetailHeader alloc] initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(128))];
        [_headView.consultBtn addTarget:self action:@selector(consultButtonAction) forControlEvents:UIControlEventTouchUpInside];
        [_headView.phoneBtn addTarget:self action:@selector(phoneFollowUpAction) forControlEvents:UIControlEventTouchUpInside];
        [_headView.historyBtn addTarget:self action:@selector(checkPatientInfoAction) forControlEvents:UIControlEventTouchUpInside];
        [_headView.baseView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkPatientInfoAction)]];
    }
    return _headView;
}

-(LGCancerPatientDetailFollowView *)followView{
    if(!_followView){
        _followView = [[LGCancerPatientDetailFollowView alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.headView.frame)+viewPix(8), Screen_W-viewPix(32), viewPix(75))];
        [_followView.addButton addTarget:self action:@selector(addFollowUpAction) forControlEvents:UIControlEventTouchUpInside];
        [_followView.moreBtn addTarget:self action:@selector(checkFollowUpDetailAction) forControlEvents:UIControlEventTouchUpInside];
        [_followView.auditBtn addTarget:self action:@selector(checkFollowUpDetailAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _followView;
}

-(LGPatientDetailItemView *)followupView{
    if(!_followupView){
        _followupView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(viewPix(16),kMaxY(self.followView.frame)+viewPix(18), Screen_W-viewPix(32), viewPix(75))];
        [_followupView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _followupView.backgroundColor = [UIColor whiteColor];
        _followupView.title = @"随访及医嘱记录";
        _followupView.contentLabel.text = @"暂无随访记录";
        [_followupView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkFollowupRecord)]];
    }
    return _followupView;
}

-(LGCancerPatientDetailItemView *)itemView{
    if(!_itemView){
        _itemView = [[LGCancerPatientDetailItemView alloc]init];
        _itemView.diseaseCode = self.diseaseCode;
        _itemView.delegate = self;
    }
    return _itemView;
}

-(LGPatientDetailMedicineView *)medicineView{
    if(!_medicineView){
        _medicineView = [[LGPatientDetailMedicineView alloc]init];
        _medicineView.delegate = self;
    }
    return _medicineView;
}


-(UIButton *)followBtn{
    if(!_followBtn){
        _followBtn = [UIButton buttonWithIcon:@"grayTipDown" title:@"查看更多" titleFont:LGFont(13) textColor:@"#909399" frame:CGRectMake(0, 0, Screen_W, viewPix(30))];
        [_followBtn setSelectTitle:@"收起更多" selectImage:@"grayTipUp"];
        [_followBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:5];
        [_followBtn addTarget:self action:@selector(checkMoreFollowRecords:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _followBtn;
}

-(NSDateFormatter *)formatter{
    if(!_formatter){
        _formatter = [[NSDateFormatter alloc]init];
        _formatter.dateFormat = @"yyyy年MM月";
    }
    return _formatter;
}

-(UIView *)bottomView{
    if(!_bottomView){
        _bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, Screen_H-topBarHeight-viewPix(50)-bottomSafeBarHeight/2.0, Screen_W, viewPix(50)+bottomSafeBarHeight/2.0)];
        _bottomView.backgroundColor = [UIColor whiteColor];
    }
    return _bottomView;
}

-(UIView *)bottomItemView{
    if(!_bottomItemView){
        CGFloat height = (isPad==YES)?viewPix(40):viewPix(90);
        _bottomItemView = [[UIView alloc]initWithFrame:CGRectMake(0, viewPix(50), Screen_W, height)];
        _bottomItemView.backgroundColor = [UIColor whiteColor];
        _bottomItemView.clipsToBounds = YES;
        _bottomItemView.alpha = 0;
    }
    return _bottomItemView;
}

-(UIButton *)openButton{
    if(!_openButton){
        _openButton = [UIButton buttonWithTitle:@"展开" titleFont:LGFont(14) textColor:@"#666666" imageName:@"grayTipDown"];
        _openButton.frame = CGRectMake(Screen_W-viewPix(60), viewPix(7), viewPix(50), viewPix(35));
        [_openButton setSelectTitle:@"收起" selectImage:@"grayTipUp"];
        [_openButton setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:3];
        [_openButton addTarget:self action:@selector(openButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _openButton;
}


-(void)createBottomView{
    UILabel *titleLabel = [UILabel lableWithText:@"操作台" colorString:@"#282828" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    titleLabel.frame = CGRectMake(viewPix(12), viewPix(12), 60, viewPix(25));
    [self.bottomView addSubview:titleLabel];
    [self.bottomView addSubview:self.openButton];
    [self.bottomView addSubview:self.bottomItemView];
    NSArray *titleArray = @[@"开具医嘱",@"添加随访总结",@"开启团队咨询",@"电话随访"];
    CGFloat itemW = (isPad==YES)?(Screen_W-viewPix(56))/5.0:(Screen_W-viewPix(40))/3.0;
    NSInteger count = (isPad==YES)?5:3;
    for (NSInteger i=0; i<titleArray.count; i++) {
        UIButton *itemBtn = [UIButton buttonWithTitle:titleArray[i] titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:kThemeColor frame:CGRectMake(viewPix(12)+(itemW+viewPix(8))*(i%count), viewPix(48)*(i/count), itemW, viewPix(40))];
        [itemBtn addBorder:kThemeColor lineWidth:1 cornerRidus:10];
        itemBtn.tag = 1000+i;
        [itemBtn addTarget:self action:@selector(bottomItemButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.bottomItemView addSubview:itemBtn];
    }
}


@end
